package start.demo01.StringAnalysis;

import java.util.HashSet;import java.util.List;import java.util.Set;import java.util.function.Predicate;import java.util.stream.Collectors;public class Match {

    private static final Set<String> SCOPE_SET = new HashSet<>();

    public static void main(String[] args){
      SCOPE_SET.add("*d");
      SCOPE_SET.add("BCE_APPMONITOR1");
      SCOPE_SET.add("BCE_*");
      System.out.println(isEnabled("BCE_BCC"));
    }

    public static boolean isEnabled(String scope) {
        return SCOPE_SET.contains("*") || SCOPE_SET.contains("BCE_APPMONITOR") || SCOPE_SET.contains(scope) || match(scope);
    }

    public static boolean match(String scope) {
        for (String s : SCOPE_SET) {
            if (s.startsWith("*")) {
                s = s.substring(1);
                if (scope.endsWith(s)) {
                    return true;
                }
            } else if (s.endsWith("*")) {
                s = s.substring(0, s.length()-1);
                if (scope.startsWith(s)) {
                    return true;
                }
            }
        }
        return false;
    }
}
